package com.example.wishstar.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.wishstar.MyApplication;
import com.example.wishstar.db.UserDao;
import com.example.wishstar.db.UserDatabase;
import com.example.wishstar.model.CommonDate;
import com.example.wishstar.model.Habit;
import com.example.wishstar.model.UpdateHabit;
import com.example.wishstar.model.UpdateWish;
import com.example.wishstar.model.Wish;
import com.example.wishstar.repository.HabitWishRepository;
import com.example.wishstar.view.UpdateHabitDialogFragment;

import java.util.List;

public class WishViewModel extends AndroidViewModel {
    private String TAG = "WishViewModel";
    private HabitWishRepository habitWishRepository;
    private int userId;
    private LiveData<List<Habit>> habitList;
    private LiveData<List<Wish>> wishList;

    public WishViewModel(@NonNull Application application) {
        super(application);

        UserDatabase userDatabase = MyApplication.getUserDatabase();
        UserDao userDao = userDatabase.userDao();
        habitWishRepository = new HabitWishRepository(userDao, MyApplication.getApi());
        userId = MyApplication.userId;
        habitList = habitWishRepository.getHabits(userId);
        wishList = habitWishRepository.getWishs(userId);
    }

    public void refresh() {
        habitWishRepository.refresh(userId);
    }

    public LiveData<List<Habit>> getHabit() {
        return habitList;
    }

    public LiveData<List<Wish>> getWish() {
        return wishList;
    }

    public void updateHabit(UpdateHabit updateHabit) {
        habitWishRepository.updateHabit(updateHabit);
    }

    public void updateWish(UpdateWish updateWish) {
        habitWishRepository.updateWish(updateWish);
    }

    public void delayWish(int wishId, CommonDate date) {
        habitWishRepository.delayWish(wishId, date);
    }

    public void deleteWishByWishId(int wishId) {
        habitWishRepository.deleteWishByWishId(wishId);
    }

    public void deleteHabitByHabitId(int habitId) {
        habitWishRepository.deleteHabitByHabitId(habitId);
    }
}
